<?php 
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;

//  获取所有销售 
//$member = 
$this->title = "优惠审批";
$status = Yii::$app->params['order_status'];
unset($status[10]);
unset($status[11]);
unset($status[12]);

$product_name = isset($params['Order']['product']['name']) ? $params['Order']['product']['name'] : '';
$product_go_time = isset($params['Order']['product']['go_time']) ? $params['Order']['product']['go_time'] : '';
?>

<h2 class="page-header"><small>优惠审批</small></h2>

<div class="sale-price-form">
    <?php $form = ActiveForm::begin([
        //'action' => ['index'],
        'method' => 'get',
        'layout' => 'inline',
        'options' => ['data-pjax'=>true],
    ]); ?>

    <!-- ?= $form->field($model, 'source')->dropdownList(Yii::$app->params['order_source'],['prompt'=>Yii::t('app.order','Source')])? -->

    <?= $form->field($model, 'product[name]')->textInput(['placeholder' => '游轮名称', 'value'=>$product_name ]) ?>

    <?= $form->field($model, 'product[go_time]')->widget(kartik\date\DatePicker::classname(),[
                                                'options' => ['placeholder' => '航线出发时间',
														'value' => $product_go_time,
													],
                                                'pluginOptions' => [
                                                    'format' => 'yyyy-mm-dd',
                                                    'autoclose'=>true,
                                                    'todayHighlight' => true
                                                ]
                                            ]); ?>

    <?= $form->field($model, 'username')->textInput(['placeholder' => Yii::t('app.order', 'Username')]) ?>

    <!-- ?= $form->field($model, 'member_id')->textInput(['placeholder' => Yii::t('app.order', 'Member ID')]) ? -->

    <?= $form->field($model, 'code')->textInput(['placeholder' => Yii::t('app.order', 'Code')]) ?>

    <?= $form->field($model, 'status')->dropdownList($status,['prompt'=>Yii::t('app.order','Status')])?>

    <div class="form-group">
        <?= Html::submitButton(Yii::t('app', 'Search'), ['class' => 'btn btn-primary']) ?>
    </div>

    <?php ActiveForm::end(); ?>
</div>

<div class="panels">
	<table class="table">
		<thead>
			<tr>
				<td>团期</td>
				<td>订单</td>
				<td>联系人</td>
				<td>舱房</td>
				<td>金额</td>
				<!-- td>优惠说明</td -->
				<td>操作</td>
			</tr>
		</thead>
	
		<?php foreach($all as $o){ ?>
			<tr>
				<td class="col-md-3">
					<p><?= $o->product->name ?> </p>
					<p>出发时间 : <?= $o->product->go_time ?></p>
				</td>
				<td>
					<p><a href="/order/order/view?id=<?= $o->id ?>" target="_blank"><?= $o->code ?></a></p>
					<p>来源 : <?= Yii::$app->params['order_source'][$o->source] ?></p>
					<p>销售 : <?= $o->member->profile->name  ?></p>
				</td>
				<td>
					<p>联系人 : <?= $o->username ?></p>
					<p>联系电话 : <?= $o->phone ?></p>
					<p><?=  Yii::$app->formatter->asRelativeTime($o->updated_at) ?></p>
				</td>
	
				<td>
					<?php
					if($o->product->stock == 1){ // 国内航线
						foreach($o->room as $room){ // orderRoom
							echo "<p>";
							echo $room->productRoom->room->name;
							echo $room->productRoom->room->code;
							echo $room->productRoom->people .'人间&nbsp;&nbsp;';
							echo " /&nbsp;&nbsp;".$o->getRoomCustomer($room->id)->count() ."人";
							echo "</p>";
						}
					}elseif($o->product->stock == 2){ // 海外航线
						$t = json_decode($o->product->rooms, true);
	
						foreach($o->room as $room){
							echo "<p>";
							print_r($t[$room->room_id]['name']);
							echo " /&nbsp;&nbsp;&nbsp;入数".$o->getRoomCustomer($room->id)->count();
							echo "</p>";
						}
					}
				?>
				</td>
	
				<td>
					<p>总金额 : <?= Yii::$app->formatter->asCurrency($o->price) ?></p>
					<p>优惠金额 : <b class="text-danger"><?= Yii::$app->formatter->asCurrency($o->sale_price) ?></b></p>
					<p><?= $o->price_desc?></p>
				</td>

				<td>
					<?php if($o->check == 1){  ?>

						<label class="label">已审核</label>		
					<?php }elseif($o->check == 2){   ?>
						<a class="btn btn-danger btn-sm check"  data-id=<?= $o->id ?> >审核</a>
					<?php }   ?>
				</td>
			</tr>
		<?php } ?>
	</table>
</div>

<?php app\components\JsBlock::begin() ?>
<script type="text/javascript">
	$(".check").click(function() {
		var id    = $(this).data("id");
		var btn  = $(this);

		var con = confirm("确定审核通过?");

		if(con == false){
			console.log(con);
			return;
		}

		$.get("/order/order/sale-price-save", { id: id }, function(data){
			//console.log(data);
			if(data){
				btn.html('审核通过');
				btn.removeClass('btn-danger');
				btn.addClass('btn-info');
			}
		})
	})
</script>
<?php app\components\JsBlock::end() ?> 
